home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / dsp / dr.bub / 96000.lha / 96000 / appb / b127.asm < prev    next >
Assembly Source File  |  1992-04-28  |  10KB  |  166 lines

  1. ; This program was originally published in the Motorola DSP96002 Users Manual
  2. ; and is provided under a DISCLAIMER OF WARRANTY available from Motorola DSP
  3. ; Operation, 6501 William Cannon Drive West, Austin, Texas 78735-8598.  For
  4. ; more information, refer to the DSP96002 Users Manual, Appendix B, DSP
  5. ; Benchmarks.
  6. ;
  7. ; B.1.27    Multibit Rotates  
  8. ;This describes how to perform multibit rotates using the logical  barrel shifts. Both the static case 
  9. ;(rotate by a fixed constant)  and the dynamic case (rotate by a value in a register) are presented.  
  10. ;The following code assumes a rotating model of the form:  
  11. ;
  12. ;       
  13. ;
  14. ;
  15. ;
  16. ;In this type of rotate, the carry participates in the bit  rotations. Bits rotated out of the register go 
  17. into the carry  bit; the previous value of the carry bit goes into the register.  
  18. ;1.    Static rotate left 1-32 bits.  The 32 bit integer to be rotated is in  d0.l.  The number of bits 
  19. ;to rotate is N.  The resulting carry is the  value of bit 32-N of the register.  For example, if 
  20. ;N=3 (three bit rotate  left), then the resulting carry will be the value of bit 29 of the  regis-
  21. ;ter.  
  22. ;
  23. ;                                                           Program    ICycles
  24. ;                                                                  Words
  25. ;      rol    d0         d0.l,d1.l  ;shift in carry, copy input 1    1
  26. ;      lsl    #N-1,d0               ;shift up, pad with zeros   1    1
  27. ;      lsr    #33-N,d1              ;shift down, set carry      1    1
  28. ;      or     d1,d0                 ;put numbers back together  1    1
  29. ;                                                              ---  ---
  30.  ;                                                     Totals:  4    4  
  31. ;
  32. ;2.     Static rotate right 1-32 bits.  The 32 bit integer to be rotated is in  d0.l.  The number of 
  33. ;bits to rotate is N.  The resulting carry is the  value of bit N-1 of the register.  For exam-
  34. ;ple, if N=3 (three bit rotate  right), then the resulting carry will be the value of bit 2 of 
  35. ;the  register.  
  36. ;
  37. ;                                                           Program    ICycles
  38. ;                                                              Words 
  39.       ror    d0         d0.l,d1.l  ;shift in carry, copy input 1     1
  40.       lsr    #N-1,d0               ;shift up, pad with zeros   1     1
  41.       lsl    #33-N,d1              ;shift down, set carry      1     1
  42.       or     d1,d0                 ;put numbers back together  1     1
  43. ;                                                              ---   ---
  44. ;                                                      Totals:  4     4  
  45.  
  46. ;3.     Dynamic rotate left 0-32 bits.  The 32 bit integer to be rotated is in  d0.l.  The number of 
  47. ;bits to rotate is in d2.l.  In the following  example, the code for checking if the shift count 
  48. ;is zero may be eliminated  if it is known that the shift count is greater than zero.  
  49. ;
  50. ;                                                           Program    ICycles
  51. ;                                                              Words  
  52.       tst    d2                    ;see if shift count is zero  1    1
  53.       jeq    _done                 ;yes, done                   2    2
  54.       rol    d0         d0.l,d1.l  ;shift in carry, copy input  1    1
  55.       dec    d2         #32,d3.l   ;dec shift count, get 32     2    2
  56.       sub    d2,d3      d2.l,d0.h  ;get 32-shift, move count    1    1
  57.       lsl    d0,d0      d3.l,d1.h  ;shift, move shift count     1    1
  58.       lsr    d1,d1                 ;shift, set carry            1    1
  59.       or     d1,d0                 ;or bits together            1    1  
  60. _done                                                          ---  ---
  61. ;                                                      Totals:  10   10  
  62.  
  63. ;4.     Dynamic rotate right 0-32 bits.  The 32 bit integer to be rotated is in  d0.l.  The number 
  64. ;of bits to rotate is in d2.l.  In the following  example, the code for checking if the shift is 
  65. ;zero count may be eliminated  if it is known that the shift count is greater than zero.  
  66. ;                                                           Program    ICycles
  67.  ;                                                             Words        
  68. tst    d2                    ;see if shift count is zero  1    1      
  69. jeq    _done                 ;yes, done                   2    2      
  70. ror    d0         d0.l,d1.l  ;shift in carry, copy input  1    1      
  71. dec    d2         #32,d3.l   ;dec shift count, get 32     2    2      
  72. sub    d2,d3      d2.l,d0.h  ;get 32-shift, move count    1    1      
  73. lsr    d0,d0      d3.l,d1.h  ;shift, move shift count     1    1      
  74. lsl    d1,d1                 ;shift, set carry            1    1      
  75. or     d1,d0                 ;or bits together            1    1  
  76. _done                                                    ---  ---
  77. ;                                               Totals:   10   10  
  78. ;The following code assumes a rotating model of the form:  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. ;In this model, the carry does not participate in the rotations.  The carry assumes the value of the bit 
  88. ;that was rotated around  the end of the register.  
  89. ;1.     Static rotate left 0-32 bits.  The 32 bit integer to be rotated is in  d0.l.  The number of bits 
  90. ;to rotate is N.  The resulting carry is the  value of bit 32-N of the register.  For example, if 
  91. ;N=3 (three bit rotate  left), then the resulting carry will be the value of bit 29 of the  regis-
  92. ;ter.  The resulting carry is the value of the least significant bit  of the register after rota-
  93. ;tion.  
  94. ;In the special case of a zero shift count, the resulting carry is the  most significant bit.  In 
  95. ;the special case of a 32 shift count, the  resulting carry is the least significant bit.  In both 
  96. ;cases, the  register shifted is unchanged.  
  97. ;
  98. ;
  99. ;                                                           Program    ICycles
  100. ;                                                              Words      
  101. move               d0.l,d1.l  ;copy input            1       1      
  102. lsr    #32-N,d0               ;shift first part      1       1      
  103. lsl    #N,d1                  ;shift other part      1       1      
  104. or     d1,d0                  ;merge bits together   1       1
  105. ;                                                    ---     ---
  106. ;                                            Totals:  4       4  
  107.  
  108.  
  109. ;2.     Static rotate right 0-32 bits.  The 32 bit integer to be rotated is in  d0.l.  The number of 
  110. ;bits to rotate is N.  The resulting carry is the  value of bit N-1 of the register.  For exam-
  111. ;ple, if N=3 (three bit rotate  right), then the resulting carry will be the value of bit 2 of 
  112. ;the  register.  The resulting carry is the value of the most significant bit  of the register af-
  113. ;ter rotation.  
  114. ;In the special case of a zero shift count, the resulting carry is the  least significant bit.  In 
  115. ;the special case of a 32 shift count, the  resulting carry is the most significant bit.  In both 
  116. ;cases, the register  shifted is unchanged.  
  117. ;
  118.  
  119. ;                                                           Program    ICycles
  120. ;                                                              Words       
  121. move               d0.l,d1.l  ;copy input             1      1      
  122. lsl    #32-N,d0               ;shift first part       1      1      
  123. lsr    #N,d1                  ;shift other part       1      1      
  124. or     d1,d0                  ;merge bits together    1      1
  125. ;                                                     ---    ---
  126. ;                                            Totals:   4      4  
  127.  
  128.  
  129. ;3.     Dynamic rotate left 0-32 bits.  The 32 bit integer to be rotated is in  d0.l.  The number of 
  130. ;bits to rotate is in d2.l.  
  131. ;In the special case of a zero shift count, the resulting carry is the  most significant bit.  In 
  132. ;the special case of a 32 shift count, the  resulting carry is the least significant bit.  In both 
  133. ;cases, the  register shifted is unchanged.  
  134. ;
  135. ;
  136. ;                                                           Program    ICycles
  137. ;                                                              Words       
  138. move    #32,d1.l              ;get 32                 1      1      
  139. sub     d2,d1      d2.l,d1.h  ;32-shift, move shift   1      1      
  140. move               d1.l,d0.h  ;move other shift       1      1      
  141. lsr     d0,d0      d0.l,d1.l  ;shift, copy input      1      1      
  142. lsl     d1,d1                 ;shift other part       1      1      
  143. or      d1,d0                 ;merge bits together    1      1
  144. ;                                                     ---    ---
  145. ;                                            Totals:   6      6 
  146. ;4.     Dynamic rotate right 0-32 bits.  The 32 bit integer to be rotated is in  d0.l.  The number 
  147. ;of bits to rotate is in d2.l.  
  148. ;In the special case of a zero shift count, the resulting carry is the  least significant bit.  In 
  149. ;the special case of a 32 shift count, the  resulting carry is the most significant bit.  In 
  150. ;both cases, the register  shifted is unchanged.  
  151. ;
  152.  
  153. ;                                                           Program    ICycles
  154. ;                                                              Words       
  155. move    #32,d1.l              ;get 32                 1      1      
  156. sub     d2,d1      d2.l,d1.h  ;32-shift, move shift   1      1      
  157. move               d1.l,d0.h  ;move other shift       1      1      
  158. lsl     d0,d0      d0.l,d1.l  ;shift, copy input      1      1      
  159. lsr     d1,d1                 ;shift other part       1      1      
  160. or      d1,d0                 ;merge bits together    1      1
  161. ;                                                     ---    ---
  162. ;                                            Totals:   6      6  
  163.